package gui.feeds;

import gui.GUIUtils;

import java.util.List;

import javax.swing.JLabel;

import core.exceptions.DBAccessException;
import core.objects.NewsFeedItem;
import core.objects.User;
import db.DBAccessEngine;
import db.threads.IDBAccessThread;

public class JFeedType3 extends JFeedComment {

	public JFeedType3(NewsFeedItem item) {
		super(item);
	}

	@Override
	protected IDBAccessThread getImageLoaderThread(final JLabel imageLabel) {
		return new IDBAccessThread() {
			
			@Override
			public Object onCreateQuery() throws DBAccessException {
				return DBAccessEngine.User().select(item.getCommentUsername());
			}
			
			@SuppressWarnings("unchecked")
			@Override
			public void onAccessFinished(Object response) {
				List<User> users = (List<User>)response;
				if (users.size() > 0)
					GUIUtils.setProfileImageAtLabel(users.get(0), imageLabel);
			}
			
			@Override
			public void onAccessFailed(DBAccessException e) {
				//empty user for non gender empty picture:
				GUIUtils.setProfileImageAtLabel(new User(0, ""), imageLabel);
			}
		};
	}

	@Override
	protected String getCommentedOn() {
		return item.getCommentUsername();
	}

	@Override
	protected void loadPlaceHoldPicture(JLabel imageLabel) {
        GUIUtils.setProfileImageAtLabel(new User(0, ""), imageLabel);
	}

	@Override
	protected String getAction() {
		return "also ranked";
	}
	
	


}
